/**
 * Created by Administrator on 2018/4/13.
 */
import {connect} from 'react-redux';
import {deleteTodo, toggleTodo} from '../actions'
import TodoList from '../components/TodoList'

const getVisibleTodos = (todos, filter) => {
	switch (filter) {
		case 'SHOW_COMPLETED':
			return todos.filter(t => t.completed)
		case 'SHOW_ACTIVE':
			return todos.filter(t => !t.completed)
		case 'SHOW_ALL':
		default:
			return todos;
	}
}

const mapStateToProps = state => ({
	todos: getVisibleTodos(state.todos, state.visibilityFilter)
})

const mapDispatchToProps = dispatch => ({
	toggleTodo: id => dispatch(toggleTodo(id)),
	deleteTodo: id => dispatch(deleteTodo(id))
})

export default connect(
	mapStateToProps,
	mapDispatchToProps
)(TodoList)